package com.zy.design.ocp.ns;

import com.zy.design.ocp.base.Notification;
import com.zy.design.ocp.base.NotificationEmergencyLevel;

/**
 * @author zhaoyi
 * @date 2021/3/15 17:53
 */
public class TpsAlertHandler extends AlertHandler {

    public TpsAlertHandler(AlertRule2 rule, Notification notification) {
        super(rule, notification);
    }

    @Override
    public void check(ApiStatInfo apiStatInfo) {
        long tps = apiStatInfo.getRequestCount()/ apiStatInfo.getDurationOfSeconds();
        if (tps > rule.getMatchedRule(apiStatInfo.getApi()).getMaxTps()) {
            notification.notify(NotificationEmergencyLevel.URGENCY, "... TpsAlertHandler");
        }
    }
}
